﻿Imports MyPOSLibrary
Imports System.Data.Common
Imports Microsoft.ApplicationBlocks.Data

Public Class MasterDataLayer
    Inherits MasterDataProvider

    Dim SQLQuery As String = String.Empty

    Public Overrides Function GetClientByID(ByVal ID As Integer) As MyPOSLibrary.Client
        Try
            Dim dr As SqlClient.SqlDataReader = Nothing
            SQLQuery = "Select * From tbl_ClientMaster Where [Client Id]=" & ID
            dr = SqlHelper.ExecuteReader(SQLConnectionString, CommandType.Text, SQLQuery)
            Dim clientObject As New Client
            If dr.Read = True Then
                clientObject.Name = dr.Item(1)
                clientObject.Address = DataCommon.DBNullCheck(dr.Item(2))
                clientObject.TelNo = DataCommon.DBNullCheck(dr.Item(3))
                clientObject.MobileNo = DataCommon.DBNullCheck(dr.Item(4))
                clientObject.ContactPerson = DataCommon.DBNullCheck(dr.Item(5))
                clientObject.Email = DataCommon.DBNullCheck(dr.Item(6))
                clientObject.Description = DataCommon.DBNullCheck(dr.Item(7))
                clientObject.VATNo = DataCommon.DBNullCheck(dr.Item(8))
                clientObject.Creditlimit = DataCommon.DBNullCheck(dr.Item(9))
            End If
            If dr.IsClosed = False Then dr.Close()
            Return clientObject
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Overrides Function GetClientList() As List(Of MyPOSLibrary.Client)
        Try
            Dim dr As SqlClient.SqlDataReader = Nothing
            SQLQuery = "Select * From tbl_ClientMaster order by 2"
            dr = SqlHelper.ExecuteReader(SQLConnectionString, CommandType.Text, SQLQuery)
            Dim clientList As New List(Of Client)
            Dim clientObject As Client
            While dr.Read
                clientObject = New Client
                clientObject.Name = dr.Item(1)
                clientObject.Address = DataCommon.DBNullCheck(dr.Item(2))
                clientObject.TelNo = DataCommon.DBNullCheck(dr.Item(3))
                clientObject.MobileNo = DataCommon.DBNullCheck(dr.Item(4))
                clientObject.ContactPerson = DataCommon.DBNullCheck(dr.Item(5))
                clientObject.Email = DataCommon.DBNullCheck(dr.Item(6))
                clientObject.Description = DataCommon.DBNullCheck(dr.Item(7))
                clientObject.VATNo = DataCommon.DBNullCheck(dr.Item(8))
                clientObject.Creditlimit = DataCommon.DBNullCheck(dr.Item(9))
                clientList.Add(clientObject)
            End While
            If dr.IsClosed = False Then dr.Close()
            Return clientList
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Overrides Function GetCompanyInfo() As MyPOSLibrary.CompanyInfo
        Try
            Dim dr As SqlClient.SqlDataReader = Nothing
            SQLQuery = "Select * From tbl_CompanyMaster "
            dr = SqlHelper.ExecuteReader(SQLConnectionString, CommandType.Text, SQLQuery)

            Dim CompanyObject As New CompanyInfo
            If dr.Read = True Then
                CompanyObject.Name = dr.Item(1)
                CompanyObject.Address = DataCommon.DBNullCheck(dr.Item(2))
                CompanyObject.Description = DataCommon.DBNullCheck(dr.Item(4))
                CompanyObject.TelNo = DataCommon.DBNullCheck(dr.Item(3))
                CompanyObject.VATNo = DataCommon.DBNullCheck(dr.Item(5))
                CompanyObject.CSTNo = DataCommon.DBNullCheck(dr.Item(6))
                CompanyObject.InvoiceTerm = DataCommon.DBNullCheck(dr.Item(7))
                If IsDBNull(dr.Item(8)) = False Then
                    If CType(dr.Item(8), Boolean) = True Then
                        'chkItemAuto.Checked = True
                    End If
                End If
                ' txtSalesBillPrefix.Text = DataCommon.DBNullCheck(dr.Item(9))
                'txtSalesBillCrNo.Text = DataCommon.DBNullCheck(dr.Item(10))
                'txtSalesBillSufix.Text = DataCommon.DBNullCheck(dr.Item(11))
                'txtJobNoPrefix.Text = DataCommon.DBNullCheck(dr.Item("POPrefix"))
                'txtJobNoCrNo.Text = DataCommon.DBNullCheck(dr.Item("POCrNo"))
                'txtJobNoSufix.Text = DataCommon.DBNullCheck(dr.Item("POSufix"))
            End If
            dr.Close()
            Return CompanyObject
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Overrides Function GetItemByID(ByVal ID As Integer) As MyPOSLibrary.Items

    End Function

    Public Overrides Function GetItemList() As System.Collections.Generic.List(Of MyPOSLibrary.Items)

    End Function

    Public Overrides Function GetLookupByID(ByVal ID As Integer) As MyPOSLibrary.Lookups

    End Function

    Public Overrides Function GetLookupList() As System.Collections.Generic.List(Of MyPOSLibrary.Lookups)

    End Function

    Public Overrides Function GetVendorByID(ByVal ID As Integer) As MyPOSLibrary.Vendor

    End Function

    Public Overrides Function GetVendorList() As System.Collections.Generic.List(Of MyPOSLibrary.Vendor)

    End Function

    Public Overrides Function SaveClient(ByVal ClientObject As MyPOSLibrary.Client) As Boolean

    End Function

    Public Overrides Function SaveCompanyInfo(ByVal CompanyInfoObject As MyPOSLibrary.CompanyInfo) As Boolean

    End Function

    Public Overrides Function SaveItem(ByVal ItemObject As MyPOSLibrary.Items) As Boolean

    End Function

    Public Overrides Function SaveLookup(ByVal LookupObject As MyPOSLibrary.Lookups) As Boolean

    End Function

    Public Overrides Function SaveVendor(ByVal VendorObject As MyPOSLibrary.Vendor) As Boolean

    End Function

    Private Property SQLConnectionString As String
    Public Sub New(ByVal SQLConnectionString As String)
        Me.SQLConnectionString = SQLConnectionString
    End Sub
End Class
